<?php
namespace Todo\Model\Sys;

use Todo\Model\MemoryModel;

class RoleModel extends MemoryModel
{
    public $tableName = 'sys_role';

    public $_validate = array(
        array('title', 'require', '请输入角色名称')
    );

    protected $_auto = array(
        array('is_default', 0, self::MODEL_INSERT)
    );

    /**
     * 删除角色前先删除角色授权的菜单
     * @param int $id 角色ID
     * @param boolean $true=false 是否假删除
     * @return bool
     */
    public function del($id, $true=false){
        $sql = 'DELETE FROM sys_role_menu WHERE role_id = '. $id;
        $this->execute($sql);

        return $this->where(array($this->getPk() => $id))->delete();
    }
}